
package com.idealighter.game.games.zjh.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.dictionary.domain.ZhajinhuaRoomDomain;
import com.idealighter.game.gamehall.dto.SeatInfo;
import com.idealighter.game.gamehall.dto.TableInfo;
import com.idealighter.game.games.zjh.ZjhPlayer;
import com.idealighter.game.games.zjh.message.ResReadyOverMsg;
import com.idealighter.game.message.ModuleMsgIdConstant;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;
import com.idealighter.utils.code.RandCodeUtil;

import java.util.concurrent.TimeUnit;

@ResMsgHandler(ModuleMsgIdConstant.Zjh.RES_READY_OVER)

public class ResReadyOverHandler implements ResMessageHandler {

  @Override
  public void action(Player player, ResMessage message) {
    ResReadyOverMsg msg = (ResReadyOverMsg) message;
    ZjhPlayer zjhPlayer = (ZjhPlayer) player;
    TableInfo table = zjhPlayer.table(player.playerId);
    ZhajinhuaRoomDomain roomDomain = ((ZjhPlayer) player).roomDomain;
    // 底注
    int base = roomDomain.getBase();
    for (SeatInfo s : table.getSeats()) {
      if (s.getPlayerId() > 0) {
        zjhPlayer.totalBet += base;
      }
    }

    if (msg.getNextOptPlayerId() == player.playerId) { // 机器人头家，暗最小注
      player.schedule(() -> {
        zjhPlayer.bet();
      }, RandCodeUtil.random(1, 10), TimeUnit.SECONDS);
    }

  }
}
